<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/weaver.tld" prefix="wea"%>
<%@ include file="/systeminfo/init_wev8.jsp"%>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="wtci" class="weaver.workflow.workflow.WorkTypeComInfo" scope="page" />
<jsp:useBean id="wci" class="weaver.workflow.workflow.WorkflowComInfo" scope="page"/>
<jsp:useBean id="rci" class="weaver.hrm.resource.ResourceComInfo" scope="page" />
<jsp:useBean id="jci" class="weaver.hrm.job.JobTitlesComInfo" scope="page" />
<jsp:useBean id="flowTypeTimeAnalyseSort" class="weaver.workflow.WorkflowReportCronJob" scope="page" />
<jsp:useBean id="NodeOverTimeInfo" class="weaver.workflow.node.NodeOverTimeInfo" scope="page" />
<%
	/*用户验证*/
	if(user==null) {
		response.sendRedirect("/login/Login.jsp");
		return;
	}

	int userId=user.getUID();

	String isSearch = Util.null2String(request.getParameter("isSearch")); // 第一次打开页面不搜索工单
	String process_number = Util.null2String(request.getParameter("process_number"));
	String errorText = "";
	ArrayList requestidMaps = new ArrayList();
	if(("1".equals(isSearch)) && (!process_number.equals("") )) {

		String sqlFrom = " from (select wr.*,h.departmentid,h.subcompanyid1  from workflow_requestbase wr  left join hrmresource h on wr.creater = h.id ) a, workflow_base b ";
		String sql = " where a.workflowid = b.id ";
		sql += " and a.requestmark = '" + process_number + "' ";
		//sql += " and a.requestid not in (select requestid from uf_bill_deliver where presentation_date = CONVERT(varchar(100),GETDATE(),23))";
		String sql1 = "select * " + sqlFrom + sql;
		//out.println("seee " +  Util.null2String(userId));
		//out.println(sql1);
		rs.executeSql(sql1);
		if (rs.next()){
			HashMap requestidMap = new HashMap();
			requestidMap.put("requestid", Util.null2String(rs.getString("requestid")));
			requestidMap.put("requestmark", Util.null2String(rs.getString("requestmark")));
			requestidMap.put("requestname", Util.null2String(rs.getString("requestname")));
			requestidMap.put("departmentid", Util.null2String(rs.getString("departmentid")));
			requestidMap.put("subcompanyid1", Util.null2String(rs.getString("subcompanyid1")));
			requestidMap.put("creater", Util.null2String(rs.getString("creater")));
			requestidMap.put("receiver", Util.null2String(userId));
			requestidMaps.add(requestidMap);
		}else{
			errorText = "系统找不到这张单，交单不成功。" ;
		}

		if (1<=requestidMaps.size())  {
			HashMap requestidMap = (HashMap) requestidMaps.get(0);
		    sql = "insert into uf_bill_deliver (requestid,requestmark,requestname,departmentid,subcompanyid1,creater,receiver,modedatacreater,modedatacreatertype,presentation_date,presentation_time,formmodeid)";
		    sql += "values ('" + requestidMap.get("requestid") + "'";
		    sql += ",'" + requestidMap.get("requestmark") + "'";
		    sql += ",'" + requestidMap.get("requestname") + "'";
			sql += ",'" + requestidMap.get("departmentid") + "'";
			sql += ",'" + requestidMap.get("subcompanyid1") + "'";
			sql += ",'" + requestidMap.get("creater") + "'";
			sql += ",'" + requestidMap.get("receiver") + "'";
			sql += ",'" + requestidMap.get("receiver") + "'";
			sql += ",'" + "0" + "'";
		    sql += ", CONVERT(varchar(10),GETDATE(),23), CONVERT(varchar(5),GETDATE(),24),10)";
		    //out.println(sql);
		    rs.execute(sql);
		    errorText = "交单成功，可以继续扫描下一张。" ;
		}
	}
	String titlename = "";
%>

<HTML>
<HEAD>
<LINK REL=stylesheet type=text/css HREF=/css/Weaver_wev8.css>
<SCRIPT language="javascript" src="/js/weaver_wev8.js"></script>
	<style type="text/css">
		.button {
			display: inline-block;
			outline: none;
			cursor: pointer;
			text-align: center;
			text-decoration: none;
			font: 16px/100% 'Microsoft yahei',Arial, Helvetica, sans-serif;
			padding: .5em 2em .55em;
			text-shadow: 0 1px 1px rgba(0,0,0,.3);
			-webkit-border-radius: .5em;
			-moz-border-radius: .5em;
			border-radius: .5em;
			-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
			-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
			box-shadow: 0 1px 2px rgba(0,0,0,.2);
		}
		.blue {
			color: #d9eef7;
			border: solid 1px #0076a3;
			background: #0095cd;
			background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5));
			background: -moz-linear-gradient(top,  #00adee,  #0078a5);
			filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#00adee', endColorstr='#0078a5');
		}
	</style>
	<script language='javascript'>
        window.onload=function() {
            document.getElementById("process_number").focus();  //激活的文本框ID
        }
	</script>
</head>
<BODY onload="refreshList1()">
<%@ include file="/systeminfo/TopTitle_wev8.jsp"%>
<%@ include file="/systeminfo/RightClickMenuConent_wev8.jsp"%>
<%@ include file="/systeminfo/RightClickMenu_wev8.jsp"%>
<!--<table id="topTitle" cellpadding="0" cellspacing="0" width="600">
	<tr>
		<td></td>
		<td class="rightSearchSpan">
			<span title="<%=SystemEnv.getHtmlLabelName(23036, user.getLanguage()) %>" class="cornerMenu"></span>
		</td>
	</tr>
</table>-->
<form action="/wtoip/finance/reimbursement/ImplementBill.jsp" method="post" name="ImplementBillForm" id="ImplementBillForm">
	<input type="hidden" name="isSearch" id="isSearch" value="1" />
	<div id="buttonDiv" style="width: 100%; height: 30px; padding-left: 200px;" >
		<INPUT  name="process_number"  id="process_number"    placeholder="请输入OA流程编号,按Enter键" TYPE="text" SIZE="29"
			   onmouseover="this.style.borderColor='black';this.style.backgroundColor='#ffd306'"
			   style="width: 106; height: 21" onmouseout="this.style.borderColor='black';this.style.backgroundColor='#ffffff'" style="border-width:1px;border-color=black">
		<button id="executeButton" onclick="execute();"  class="button blue" >确认收单</button>
	</div>
</form>
<div id="errorText" style="width: 100%; height: 30px; padding-left: 200px;">
<p><br><br><%=Util.null2String(errorText)%></p>
</div>
</body>
<script type="text/javascript">
    function refreshList1() {
        //alert ('输入完毕，刷新列表');
        parent.refreshList();
        process_number.focus();
    }
</script>
<script type="text/javascript">
function execute() {
    jQuery("#isSearch").val(1);
    ImplementBillForm.submit();
    //parent.refreshList();
}
</script>
<script language='javascript'>
    document.onkeydown=function(){
        if (event.keyCode == 13){
            execute();
        }
    }
</script>
</html>